package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

public class Practice10HistogramView extends View {

    public Practice10HistogramView(Context context) {
        super(context);
    }

    public Practice10HistogramView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice10HistogramView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        综合练习
//        练习内容：使用各种 Canvas.drawXXX() 方法画直方图

        Paint paint =new Paint();
        paint.setAntiAlias(true);

        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(1);
//        练习内容：使用 canvas.drawLine() 方法画直线

        canvas.drawLine(100,100,100,300,paint);
        canvas.drawLine(100,300,600,300,paint);

        paint.setColor(Color.GREEN);
        Rect rect = new Rect(120,300,160,-360);
        canvas.drawRect(rect,paint);
        paint.setTextSize(16);
        canvas.drawText("Monday",110,320,paint);

        paint.setColor(Color.GREEN);
        Rect rect1 = new Rect(180,150,240,300);
        canvas.drawRect(rect1,paint);
        paint.setTextSize(16);
        canvas.drawText("Tuesday",180,320,paint);

        paint.setColor(Color.GREEN);
        Rect rect2 = new Rect(280,180,340,300);
        canvas.drawRect(rect2,paint);
        paint.setTextSize(16);
        canvas.drawText("Wednesday",280,320,paint);
    }
}
